﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class ConnectionMethodForm : System.Windows.Forms.Form
	{
		public ConnectionMethodForm()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.rboValveConnection.Checked)
			{
				this.connectionType = 1;
			}
			this.UserSettingWrite();
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void ConnectionMethodForm_Load(object sender, EventArgs e)
		{
			if (this.rboDirectConnection.Checked)
			{
				this.hytbDistance.Enabled = false;
			}
			this.UserSettingRead();
		}

		private void UserSettingWrite()
		{
			ConnectionTypeParam connectionTypeParam = new ConnectionTypeParam();
			connectionTypeParam.Distance = Convert.ToDouble(this.hytbDistance.Text);
			connectionTypeParam.Type = 0;
			if (this.rboValveConnection.Checked)
			{
				connectionTypeParam.Type = 1;
			}
			this.userSetting.WriteConnectionType(connectionTypeParam);
			this.distance = Convert.ToDouble(this.hytbDistance.Text);
		}

		private void UserSettingRead()
		{
			ConnectionTypeParam connectionTypeParam = this.userSetting.GetConnectionType();
			this.hytbDistance.Text = connectionTypeParam.Distance.ToString();
			if (connectionTypeParam.Type == 0)
			{
				this.rboDirectConnection.Checked = true;
				return;
			}
			this.rboValveConnection.Checked = true;
		}

		private void rboDirectConnection_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rboDirectConnection.Checked)
			{
				this.hytbDistance.Enabled = false;
				return;
			}
			this.hytbDistance.Enabled = true;
		}

		private void rboValveConnection_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rboValveConnection.Checked)
			{
				this.hytbDistance.Enabled = true;
				return;
			}
			this.hytbDistance.Enabled = false;
		}

		public int connectionType;

		private HVACUserSetting userSetting = new HVACUserSetting();

		public double distance;
	}
}
